#include "TestTradeSpi.hpp"
#include "TestContext.hpp"
#include <stdio.h>
#include <iostream>
using namespace std;

void TestSecuTradeSpi::OnFrontConnected()
{
	printf("连接成功\n");
}

void TestSecuTradeSpi::Start()
{
	pthread_t DealBusinessTrd;
	int ret = pthread_create(&DealBusinessTrd, NULL, DealBusiness, NULL);
	if (ret != 0)
	{
		cout << "create thread error" << endl;
	}
}

void* TestSecuTradeSpi::DealBusiness(void* lpvoid)
{
	int times = 0;
	while (true)
	{
		printf("请求次数:%d\n", times);
		int cmd;
		int reset = 0;
		cout<<"请选择功能:                                  " << endl;
		cout<<"[1]接入认证                                  " << endl;
		cout<<"[2]客户登录                                  " << endl;
		//cout<<"[2]客户密码修改                              " << endl;
		//cout<<"[3]客户资金调拨                              " << endl;
		//cout<<"[4]客户股份调拨                              " << endl;
		cout<<"[5]委托录入                                  " << endl;
		cout<<"[6]委托撤回                                  " << endl;
		//cout<<"[7]委托查询                                  " << endl;
		//cout<<"[8]成交查询                                  " << endl;
		//cout<<"[9]资金查询                                  " << endl;
		cout<<"[10]持仓查询                                 " << endl;
		//cout<<"[11]新股申购额度查询                         " << endl;
		//cout<<"[12]证券代码信息查询                         " << endl;
		//cout<<"[13]ETF代码信息查询                          " << endl;
		//cout<<"[14]ETF成分股信息查询                        " << endl;
		//cout<<"[15]质押入库债券明细查询                     " << endl;
		//cout<<"[16]客户债券质押回购托管比查询               " << endl;
		//cout<<"[17]客户债券入库集中度查询                   " << endl;
		//cout<<"[18]担保证券信息查询                         " << endl;
		//cout<<"[19]标的证券信息查询                         " << endl;
		//cout<<"[20]可融资金查询                             " << endl;
		//cout<<"[21]可融证券查询                             " << endl;
		//cout<<"[22]两融利率查询                             " << endl;
		//cout<<"[23]信用资产查询                             " << endl;
		//cout<<"[24]代扣收明细查询                           " << endl;
		//cout<<"[25]两融合约查询                             " << endl;
		//cout<<"[26]现金还款                                 " << endl;
		cout<<"[27]银行账户查询                               " << endl;
		cout<<"[0]退出                                      " << endl;
		cout<<"输入功能选项:                                " << endl;
		cin >> cmd;
		switch (cmd)
		{
		case 1:
		{
			CHSSecuReqAuthenticateField stHSSecuReqAuthenticate;
			memset(&stHSSecuReqAuthenticate, 0, sizeof(stHSSecuReqAuthenticate));
			string UserName;
			string Authcode;
			string Appid;
			cout << "输入客户端ID:" << endl;
			cin >> Appid;
			cout << "输入资产账号:" << endl;
			cin >> UserName;
			cout << "输入认证码:" << endl;
			cin >> Authcode;
			strcpy(stHSSecuReqAuthenticate.AppID, Appid.c_str());
			strcpy(stHSSecuReqAuthenticate.AccountID, UserName.c_str());
			strcpy(stHSSecuReqAuthenticate.AuthCode, Authcode.c_str());
			int iRet = TestContext::GetTestTradeApi()->ReqAuthenticate(&stHSSecuReqAuthenticate, TestContext::GetIncRequestNo());
			if (iRet != 0)
			{
				printf("%s\n", TestContext::GetTestTradeApi()->GetApiErrorMsg(iRet));
			}
			reset = 1;
		}
		break;
		case 2:
		{
			CHSSecuReqUserLoginField stHSReqUserLogin;
			memset(&stHSReqUserLogin, 0, sizeof(CHSSecuReqUserLoginField));
			string UserName;
			string PassWord;
			cout << "输入资产账号:" << endl;
			cin >> UserName;
			cout << "输入密码:" << endl;
			cin  >> PassWord;
			strcpy(stHSReqUserLogin.AccountID, UserName.c_str());
			strcpy(stHSReqUserLogin.Password, PassWord.c_str());
			stHSReqUserLogin.UserApplicationType = '4';
			strcpy(stHSReqUserLogin.UserStationInfo, "demo");
			int iRet = TestContext::GetTestTradeApi()->ReqUserLogin(&stHSReqUserLogin, TestContext::GetIncRequestNo());
			if (iRet != 0)
			{
				printf("%s\n", TestContext::GetTestTradeApi()->GetApiErrorMsg(iRet));
			}
			reset = 1;
		}
		break;
		//case 2:
		//{
		//	CHSSecuReqUserPasswordUpdateField pReqUserPasswordUpdate;
		//	memset(&pReqUserPasswordUpdate, 0, sizeof(CHSSecuReqUserPasswordUpdateField));

		//	int iRet = TestContext::GetTestTradeApi()->ReqUserPasswordUpdate(&pReqUserPasswordUpdate, TestContext::GetIncRequestNo());
		//	/*int numbers = 0;
		//	int i;
		//	CppSQLite3DB m_apiPushCache;
		//	CppSQLite3Statement m_apiPushInsertStat;
		//	char cacheFileName[32] = "";
		//	strcpy(cacheFileName, "HSAPI_20181130_10000014");
		//	m_apiPushCache.open(cacheFileName);
		//	if (!m_apiPushCache.tableExists("apipushcache"))
		//	{
		//		m_apiPushCache.execDML("CREATE TABLE [apipushcache] ([push_serial_no] INTEGER  NOT NULL PRIMARY KEY,[APIEntrustPushClob] BLOB  NOT NULL)");
		//	}
		//	m_apiPushInsertStat = m_apiPushCache.compileStatement("insert into [apipushcache] values (?, ?);");*/
		//	/*CHSApiEntrustPushField *pClob;
		//	pClob->init_date = 20181130;
		//	strcpy(pClob->fund_account, "10000014");
		//	struct timeval t1, t2;
		//	gettimeofday(&t1, NULL);
		//	for (i = 0; i < 10000; i++)
		//	{
		//		pClob->push_serial_no = i;
		//		m_apiPushInsertStat.bind(1, pClob->push_serial_no);
		//		m_apiPushInsertStat.bind(2, (unsigned const char*)pClob, sizeof(CHSApiEntrustPushField));
		//		try
		//		{
		//			m_apiPushInsertStat.execDML();
		//			numbers++;
		//		}
		//		catch (exception e)
		//		{

		//		}
		//		m_apiPushInsertStat.reset();
		//	}
		//	gettimeofday(&t2, NULL);
		//	int t = (t2.tv_sec - t1.tv_sec) * 1000000 + t2.tv_usec - t1.tv_usec;
		//	printf("发出时间:%ld\n", t);
		//	printf("成功次数:%d\n", numbers);*/
		//}
		//reset = 1; break;
		//case 3:cout << "客户资金调拨成功" << endl; reset = 1; break;
		//case 4:cout << "客户股份调拨成功" << endl; reset = 1; break;
		case 5:
		{
			CHSSecuReqOrderInsertField stHSReqOrderInsert;
			memset(&stHSReqOrderInsert, 0, sizeof(CHSSecuReqOrderInsertField));
			string ExchangeID;
			cout << "输入市场, [1]上海 [2]深圳:" << endl;
			cin >> ExchangeID;
			strcpy(stHSReqOrderInsert.ExchangeID, ExchangeID.c_str());
			string StockCode;
			cout << "输入证券代码:" << endl;
			cin >> StockCode;
			strcpy(stHSReqOrderInsert.StockCode, StockCode.c_str());
			int Direction;
			cout << "输入报单方向:" << endl;
			cin >> Direction;
			stHSReqOrderInsert.Direction = Direction;
			int OrderCommand;
			cout << "输入报单指令:" << endl;
			cin >> OrderCommand;
			stHSReqOrderInsert.OrderCommand = OrderCommand;
			double OrderPrice;
			cout << "输入价格:" << endl;
			cin >> OrderPrice;
			stHSReqOrderInsert.OrderPrice = OrderPrice;
			double OrderVolume;
			cout << "输入买卖数量:" << endl;
			cin >> OrderVolume;
			stHSReqOrderInsert.OrderVolume = OrderVolume;
			//for (int i = 0; i < 10000; i++)
			//{
				int iRet = TestContext::GetTestTradeApi()->ReqOrderInsert(&stHSReqOrderInsert, TestContext::GetIncRequestNo());
				if (iRet != 0)
					printf("error\n");
			//}
		}
		reset = 1; break;
		case 6:
		{
			CHSSecuReqOrderActionField stReqOrderAction;
			memset(&stReqOrderAction, 0, sizeof(CHSSecuReqOrderActionField));
			// string BrokerOrderID;
			// cout << "输入报单编码:" << endl;
			// cin >> BrokerOrderID;
			// strcpy(stReqOrderAction.BrokerOrderID, BrokerOrderID.c_str());
			// int OrderPartition;
			// cout << "输入报单分区:" << endl;
			// cin >> OrderPartition;
			// stReqOrderAction.OrderPartition = OrderPartition;
			int64 ClientOrderID;
			cout << "输入客户端报单编号:" << endl;
			cin >> ClientOrderID;
			stReqOrderAction.ClientOrderID = ClientOrderID;
			int iRet = TestContext::GetTestTradeApi()->ReqOrderAction(&stReqOrderAction, TestContext::GetIncRequestNo());
			if (iRet != 0)
				printf("error\n");
		}
		reset = 1; break;
		//case 7:cout << "委托查询成功" << endl; reset = 1; break;
		//case 8:cout << "成交查询成功" << endl; reset = 1; break;
		//case 9:cout << "资金查询成功" << endl; reset = 1; break;
		//case 10:cout << "持仓查询成功" << endl; reset = 1; break;
		case 10:
		{
			CHSSecuReqQryHoldField stHSSecuReqQryHold;
			memset(&stHSSecuReqQryHold, 0, sizeof(CHSSecuReqQryHoldField));
			string ExchangeID;
			cout << "输入市场, [1]上海 [2]深圳:" << endl;
			cin >> ExchangeID;
			strcpy(stHSSecuReqQryHold.ExchangeID, ExchangeID.c_str());
			string StockCode;
			cout << "输入证券代码:" << endl;
			cin >> StockCode;
			strcpy(stHSSecuReqQryHold.StockCode, StockCode.c_str());
			int iRet = TestContext::GetTestTradeApi()->ReqQryHold(&stHSSecuReqQryHold, TestContext::GetIncRequestNo());
			if (iRet != 0)
				printf("error\n");
		}
		reset = 1; break;
		//case 11:cout << "新股申购额度查询成功" << endl; reset = 1; break;
		//case 12:
		//{
		//	/*CHSSecuReqQryStkcodeField stHSReqQryStkcode;
		//	memset(&stHSReqQryStkcode, 0, sizeof(CHSSecuReqQryStkcodeField));
		//	int iRet = TestContext::GetTestTradeApi()->ReqQryStkcode(&stHSReqQryStkcode, TestContext::GetIncRequestNo());
		//	if (iRet != 0)
		//	{
		//		printf("%s\n", TestContext::GetTestTradeApi()->GetApiErrorInfo(iRet));
		//	}*/
		//}
		//reset = 1; break;
		//case 13:
		//{
		//	int i;
		//	int flag = 0;
		//	CHSSecuReqQryEtfcodeField stHSReqQryEtfcode;
		//	memset(&stHSReqQryEtfcode, 0, sizeof(CHSSecuReqQryEtfcodeField));
		//	strcpy(stHSReqQryEtfcode.ExchangeID, "1");
		//	strcpy(stHSReqQryEtfcode.EtfCode, "510011");
		//	//printf("4\n");
		//	//for (i = 0; i++; i < 10)
		//	//{
		//		int iRet = TestContext::GetTestTradeApi()->ReqQryEtfcode(&stHSReqQryEtfcode, TestContext::GetIncRequestNo());
		//		//printf("1\n");
		//		//if (iRet == -1013)
		//		//{
		//			//flag++;
		//		//}
		//	//}
		//	//printf("%d\n", flag);
		//}
		//reset = 1;
		//break;
		//case 14:cout << "ETF成分股信息查询成功" << endl; reset = 1; break;
		//case 15: {
		//	CHSSecuReqQryImpawnDetailField stHSReqQryImpawnDetail;
		//	memset(&stHSReqQryImpawnDetail, 0, sizeof(CHSSecuReqQryImpawnDetailField));
		//	int iRet = TestContext::GetTestTradeApi()->ReqQryImpawnDetail(&stHSReqQryImpawnDetail, TestContext::GetIncRequestNo());
		//	if (iRet != 0)
		//	{
		//		TestContext::GetTestTradeApi()->GetApiErrorInfo(iRet);
		//	}
		//
		//}reset = 1; break;
		//case 16:cout << "客户债券质押回购托管比查询成功" << endl; reset = 1; break;
		//case 17:
		//{
		//	//int i;
		//	CHSSecuReqQryBondImpawnConcField stHSReqQryBondImpawnConc;
		//	memset(&stHSReqQryBondImpawnConc, 0, sizeof(CHSSecuReqQryBondImpawnConcField));
		//	//for (i = 0; i++; i < 100)
		//	//{
		//		int iRet = TestContext::GetTestTradeApi()->ReqQryBondImpawnConc(&stHSReqQryBondImpawnConc, TestContext::GetIncRequestNo());
		//		//if (iRet != 0)
		//		//{
		//			//printf("2\n");
		//		//}
		//		//printf("1\n");
		//	//}
		//}
		//reset = 1; break;
		//case 18:cout << "担保证券信息查询成功" << endl; reset = 1; break;
		//case 19:cout << "标的证券信息查询成功" << endl; reset = 1; break;
		//case 20:cout << "可融资金查询成功" << endl; reset = 1; break;
		//case 21:cout << "可融证券查询成功" << endl; reset = 1; break;
		//case 22:cout << "两融利率查询成功" << endl; reset = 1; break;
		//case 23:cout << "信用资产查询成功" << endl; reset = 1; break;
		//case 24:cout << "代扣收明细查询成功" << endl; reset = 1; break;
		//case 25:cout << "两融合约查询成功" << endl; reset = 1; break;
		//case 26:cout << "现金还款成功" << endl; reset = 1; break;
		case 27:
		{
			CHSSecuReqQryBankAccountField stHSReqBankAccount;
			memset(&stHSReqBankAccount, 0, sizeof(CHSSecuReqQryBankAccountField));
			string BankID;
			cout << "输入银行代码:" << endl;
			cin >> BankID;
			char CurrencyID;
			cout << "输入币种:" << endl;
			cin >> CurrencyID;
			strcpy(stHSReqBankAccount.BankID, BankID.c_str());
			stHSReqBankAccount.CurrencyID = CurrencyID;
			int iRet = TestContext::GetTestTradeApi()->ReqQryBankAccount(&stHSReqBankAccount, TestContext::GetIncRequestNo());
			if (iRet != 0)
			{
				printf("%s\n", TestContext::GetTestTradeApi()->GetApiErrorMsg(iRet));
			}
			reset = 1;
			break;
		}
		case 0:reset = 0; break;
		}
		if (1 == reset)
		{
			getchar();
			getchar();
			system("clear");
			continue;
		}
		else
		{
			TestContext::GetTestTradeApi()->ReleaseApi();
			break;
		}
	}
}
void TestSecuTradeSpi::OnFrontDisconnected(int nResult)
{
	printf("连接失败，错误信息:%s\n", TestContext::GetTestTradeApi()->GetApiErrorMsg(nResult));
	//printf("%s\n", lpTradeApi->GetApiErrorInfo(iRet));
	//TestContext::GetView()->ShowConnectResult(nResult, lpUserApi->GetApiErrorInfo(nResult));
	return;
}
bool TestSecuTradeSpi::IsErrorRspInfo(CHSSecuRspInfoField *pRspInfo)
{
	bool ret = ((pRspInfo) && (pRspInfo->ErrorID != 0));
	return ret;
}

void TestSecuTradeSpi::OnRspAuthenticate(CHSSecuRspAuthenticateField *pRspAuthenticate, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
	if (true == IsErrorRspInfo(pRspInfo))
	{
		printf("接入认证失败,错误信息:%s\n", pRspInfo->ErrorMsg);
	}
	else
	{
		printf("接入认证成功\n");
	}
}

void TestSecuTradeSpi::OnRspUserLogin(CHSSecuRspUserLoginField *pRspUserLogin, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
	if (true == IsErrorRspInfo(pRspInfo))
	{
		printf("登录失败,错误信息:%s\n", pRspInfo->ErrorMsg);
	}
	else
	{
		printf("登录成功\n");
	}
}
void TestSecuTradeSpi::OnRspQryBankAccount(CHSSecuRspQryBankAccountField *pRspBankAccount, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
	if (true == IsErrorRspInfo(pRspInfo))
	{
	}
	else if (!pRspBankAccount && bIsLast == true)
	{
	}
	else
	{
	}
}
//void TestSecuTradeSpi::OnRspUserPasswordUpdate(CHSSecuRspUserPasswordUpdateField *pRspUserPasswordUpdate, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowPasswordChangedResult(pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspUserPasswordUpdate && bIsLast == true)
//	{
//		TestContext::GetView()->ShowPasswordChangedResult(pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (pRspInfo->ErrorID == 0)
//	{
//		TestContext::GetView()->ShowPasswordChangedResult(0, "密码修改成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryBondImpawnConc(CHSSecuRspQryBondImpawnConcField *pRspQryBondImpawnConc, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		printf("3fail\n");
//	}
//	else if (!pRspQryBondImpawnConc && bIsLast == true)
//	{
//		printf("3error\n");
//	}
//	else
//	{
//		printf("3\n");
//	}
//}
//void TestSecuTradeSpi::OnRspQryTrusteeRatio(CHSSecuRspQryTrusteeRatioField *pRspQryTrusteeRatio, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryTrusteeRatioResult(pRspQryTrusteeRatio, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryTrusteeRatio && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryTrusteeRatioResult(pRspQryTrusteeRatio, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryTrusteeRatioResult(pRspQryTrusteeRatio, 0, "客户债券质押回购托管比查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryImpawnDetail(CHSSecuRspQryImpawnDetailField *pRspQryImpawnDetail, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		
//	}
//	else if (!pRspQryImpawnDetail && bIsLast == true)
//	{
//		
//	}
//	else
//	{
//		printf("响应次数:%d\n", Rsp_times);
//		printf("map大小:%d\n", EntrustListMap.size());
//	}
//}
//void TestSecuTradeSpi::OnRspUserStockTransfer(CHSSecuRspUserStockTransferField *pRspUserStockTransfer, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowStockTransferResult(pRspUserStockTransfer, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspUserStockTransfer && bIsLast == true)
//	{
//		TestContext::GetView()->ShowStockTransferResult(pRspUserStockTransfer, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowStockTransferResult(pRspUserStockTransfer, 0, "股份调拨成功");
//	}
//}
//void TestSecuTradeSpi::OnRspUserFundTransfer(CHSSecuRspUserFundTransferField *pRspUserFundTransfer, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowFundTransferResult(pRspUserFundTransfer, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspUserFundTransfer && bIsLast == true)
//	{
//		TestContext::GetView()->ShowFundTransferResult(pRspUserFundTransfer, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowFundTransferResult(pRspUserFundTransfer, 0, "资金调拨成功");
//	}
//}
//void TestSecuTradeSpi::OnRspCashRepay(CHSSecuRspCashRepayField *pRspCashRepay, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowRspCashRepayResult(pRspCashRepay, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspCashRepay && bIsLast == true)
//	{
//		TestContext::GetView()->ShowRspCashRepayResult(pRspCashRepay, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowRspCashRepayResult(pRspCashRepay, 0, "现金还款成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryCompact(CHSSecuRspQryCompactField *pRspQryCompact, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryCompactResult(pRspQryCompact, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryCompact && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryCompactResult(pRspQryCompact, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryCompactResult(pRspQryCompact, 0, "两融合约查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryPendfare(CHSSecuRspQryPendfareField *pRspQryPendfare, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryPendfareResult(pRspQryPendfare, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryPendfare && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryPendfareResult(pRspQryPendfare, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryPendfareResult(pRspQryPendfare, 0, "代扣收明细查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryCreditAsset(CHSSecuRspQryCreditAssetField *pRspQryCreditAsset, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryCreditAssetResult(pRspQryCreditAsset, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryCreditAsset && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryCreditAssetResult(pRspQryCreditAsset, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryCreditAssetResult(pRspQryCreditAsset, 0, "信用资产查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryCreditRate(CHSSecuRspQryCreditRateField *pRspQryCreditRate, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryCreditRateResult(pRspQryCreditRate, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryCreditRate && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryCreditRateResult(pRspQryCreditRate, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryCreditRateResult(pRspQryCreditRate, 0, "两融利率查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryEnsloStock(CHSSecuRspQryEnsloStockField *pRspQryEnsloStock, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryEnsloStockResult(pRspQryEnsloStock, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryEnsloStock && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryEnsloStockResult(pRspQryEnsloStock, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryEnsloStockResult(pRspQryEnsloStock, 0, "可融证券查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryEnfinFund(CHSSecuRspQryEnfinFundField *pRspQryEnfinFund, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryEnfinFundResult(pRspQryEnfinFund, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryEnfinFund && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryEnfinFundResult(pRspQryEnfinFund, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryEnfinFundResult(pRspQryEnfinFund, 0, "可融资金查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryCreditUnderlying(CHSSecuRspQryCreditUnderlyingField *pRspQryCreditUnderlying, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryCreditUnderlyingResult(pRspQryCreditUnderlying, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryCreditUnderlying && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryCreditUnderlyingResult(pRspQryCreditUnderlying, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryCreditUnderlyingResult(pRspQryCreditUnderlying, 0, "标的证券信息查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryCreditCollateral(CHSSecuReqQryCreditCollateralField *pRspQryCreditCollateral, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryCreditCollateralResult(pRspQryCreditCollateral,pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryCreditCollateral && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryCreditCollateralResult(pRspQryCreditCollateral, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryCreditCollateralResult(pRspQryCreditCollateral, 0, "担保证券信息查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryEtfcomponent(CHSSecuRspQryEtfcomponentField *pRspQryEtfcomponent, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryEtfcomponentResult(pRspQryEtfcomponent,pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryEtfcomponent && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryEtfcomponentResult(pRspQryEtfcomponent, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryEtfcomponentResult(pRspQryEtfcomponent,0, "ETF成分股信息查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryEtfcode(CHSSecuRspQryEtfcodeField *pRspQryEtfcode, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		//printf("3NULL\n");
//	}
//	else if (!pRspQryEtfcode && bIsLast == true)
//	{
//		//printf("3FAIL\n");
//	}
//	else
//	{
//
//	}
//}
//void TestSecuTradeSpi::OnRspQryStkcode(CHSSecuRspQryStkcodeField *pRspQryStkcode, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		
//	}
//	else if (!pRspQryStkcode && bIsLast == true)
//	{
//		
//	}
//	else
//	{
//		printf("响应次数:%d\n", Rsp_times);
//	}
//}
//void TestSecuTradeSpi::OnRspQryEquity(CHSSecuRspQryEquityField *pRspQryEquity, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryEquityResult(pRspQryEquity, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryEquity && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryEquityResult(pRspQryEquity, pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryEquityResult(pRspQryEquity, 0, "新股申购额度查询成功");
//	}
//}
void TestSecuTradeSpi::OnRspQryHold(CHSSecuRspQryHoldField *pRspQryPosition, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
	if (true == IsErrorRspInfo(pRspInfo))
	{
	}
	else if (!pRspQryPosition && bIsLast == true)
	{
	}
	else
	{
	}
}
//void TestSecuTradeSpi::OnRspQryFund(CHSSecuRspQryFundField *pRspQryTradingAccount, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		TestContext::GetView()->ShowQryFundResult(pRspQryTradingAccount, pRspInfo->ErrorID, pRspInfo->ErrorMsg, nRequestID);
//	}
//	else if (!pRspQryTradingAccount && bIsLast == true)
//	{
//		TestContext::GetView()->ShowQryFundResult(pRspQryTradingAccount, pRspInfo->ErrorID, pRspInfo->ErrorMsg, nRequestID);
//	}
//	else
//	{
//		TestContext::GetView()->ShowQryFundResult(pRspQryTradingAccount, 0,"资金查询成功", nRequestID);
//	}
//}
//void TestSecuTradeSpi::OnRspQryOrder(CHSSecuOrderField *pRspQryOrder, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		//TestContext::GetView()->ShowQryOrderResult(pRspQryOrder,pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryOrder && bIsLast == true)
//	{
//		//TestContext::GetView()->ShowQryOrderResult(pRspQryOrder,pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		//TestContext::GetView()->ShowQryOrderResult(pRspQryOrder,0, "委托查询成功");
//	}
//}
//void TestSecuTradeSpi::OnRspQryTrade(CHSSecuTradeField *pRspQryTrade, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
//{
//	if (true == IsErrorRspInfo(pRspInfo))
//	{
//		//TestContext::GetView()->ShowQryTradeResult(pRspQryTrade,pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else if (!pRspQryTrade && bIsLast == true)
//	{
//		//TestContext::GetView()->ShowQryTradeResult(pRspQryTrade,pRspInfo->ErrorID, pRspInfo->ErrorMsg);
//	}
//	else
//	{
//		//TestContext::GetView()->ShowQryTradeResult(pRspQryTrade,0, "成交查询成功");
//	}
//}
void TestSecuTradeSpi::OnRspOrderInsert(CHSSecuRspOrderInsertField *pRspOrderInsert, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
	if (true == IsErrorRspInfo(pRspInfo))
	{
	}
	else if (!pRspOrderInsert && bIsLast == true)
	{
	}
	else
	{
	}
}

//void TestSecuTradeSpi::OnRtnRealtime(CHSApiEntrustPushField *pRtnTrade)
//{
//	UpdateEntrust(pRtnTrade);
//	UpdateRealtime(pRtnTrade);
//	//TestContext::GetView()->ShowRtnTradeResult(pRtnTrade);
//}
//void TestSecuTradeSpi::OnRtnEntrust(CHSApiEntrustPushField *pRtnOrder)
//{
//	/*static int n = 0;
//	if(20006==n)
//	{
//		gettimeofday(&time1, NULL);
//	}
//	if (30005 == n)
//	{
//		gettimeofday(&time2, NULL);
//		int t = (time2.tv_sec - time1.tv_sec) * 1000000 + time2.tv_usec - time1.tv_usec;
//		printf("响应发出时间:%d\n", t);
//	}
//	n++;*/
//	//printf("[%d]\n",n);
//	UpdateEntrust(pRtnOrder);
//	//TestContext::GetView()->ShowRtnOrderResult(pRtnOrder);
//}
//void TestSecuTradeSpi::UpdateEntrust(CHSApiEntrustPushField *pRtnOrder)
//{
//	std::string key = pRtnOrder->entrust_id;
//	ENTRUST_MAP_ITER it = EntrustListMap.find(key);
//	if (it == EntrustListMap.end())
//	{
//		CHSSecuRspQryOrderField info;		
//		info.init_date = pRtnOrder->init_date;
//		strcpy(info.entrust_id, pRtnOrder->entrust_id);
//		strcpy(info.fund_account, pRtnOrder->fund_account);
//		strcpy(info.exchange_type, pRtnOrder->exchange_type);
//		strcpy(info.stock_account, pRtnOrder->stock_account);
//		strcpy(info.entrust_reference, pRtnOrder->entrust_reference);
//		info.batch_no = pRtnOrder->batch_no;
//		strcpy(info.stock_code, pRtnOrder->stock_code);
//		strcpy(info.entrust_prop, pRtnOrder->entrust_prop);
//		info.entrust_type = pRtnOrder->entrust_type;
//		info.entrust_bs = pRtnOrder->entrust_bs;
//		info.entrust_price = pRtnOrder->entrust_price;
//		info.entrust_amount = pRtnOrder->entrust_amount;
//		info.entrust_status = pRtnOrder->entrust_status;
//		strcpy(info.cancel_info, pRtnOrder->cancel_info);
//		info.report_time = pRtnOrder->report_time;
//		strcpy(info.report_seat, pRtnOrder->report_seat);
//		EntrustListMap[key] = info;
//	}
//	else
//	{
//		CHSSecuRspQryOrderField* lpInfo = &(it->second);
//		lpInfo->report_time = pRtnOrder->report_time;
//		lpInfo->entrust_status = pRtnOrder->entrust_status;
//	}
//}
//void TestSecuTradeSpi::UpdateRealtime(CHSApiEntrustPushField *pRtnTrade)
//{
//	//std::string key = pRtnTrade->entrust_id;
//	//TRADE_MAP_ITER it = TradeListMap.find(key);
//	//if (it == TradeListMap.end())
//	//{
//	//	std::vector<CHSSecuRspQryTradeField> tradevector;
//	//	CHSSecuRspQryTradeField info;
//	//	info.init_date = pRtnTrade->init_date;
//	//	strcpy_s(info.fund_account, pRtnTrade->fund_account);
//	//	strcpy_s(info.entrust_id, pRtnTrade->entrust_id);
//	//	strcpy_s(info.business_id, pRtnTrade->business_id);
//	//	info.business_amount = pRtnTrade->business_amount;
//	//	info.business_price = pRtnTrade->business_price;
//	//	info.business_time = pRtnTrade->business_time;
//	//	info.real_status = pRtnTrade->real_status;
//	//	info.real_type = pRtnTrade->real_type;
//	//	tradevector.insert(tradevector.end(), info);
//	//	TradeListMap[key] = tradevector;
//	//}
//	//else
//	//{
//	//	CHSSecuRspQryTradeField info;
//	//	info.init_date = pRtnTrade->init_date;
//	//	strcpy_s(info.fund_account, pRtnTrade->fund_account);
//	//	strcpy_s(info.entrust_id, pRtnTrade->entrust_id);
//	//	strcpy_s(info.business_id, pRtnTrade->business_id);
//	//	info.business_amount = pRtnTrade->business_amount;
//	//	info.business_price = pRtnTrade->business_price;
//	//	info.business_time = pRtnTrade->business_time;
//	//	info.real_status = pRtnTrade->real_status;
//	//	info.real_type = pRtnTrade->real_type;
//	//	it->second.insert(it->second.end(), info);
//	//}
//}
void TestSecuTradeSpi::OnRspOrderAction(CHSSecuRspOrderActionField *pRspOrderAction, CHSSecuRspInfoField *pRspInfo, int nRequestID, bool bIsLast)
{
	
	if (true == IsErrorRspInfo(pRspInfo))
	{
	}
	else if (!pRspOrderAction && bIsLast == true)
	{
	}
	else
	{
	}
}

void TestSecuTradeSpi::OnRtnOrder(CHSSecuOrderField *pRtnOrder)
{
}
void TestSecuTradeSpi::OnRtnTrade(CHSSecuTradeField *pRtnTrade)
{}